package org.wu.framework.inner.lazy.orm.spring.prop;

import lombok.Data;
import lombok.Getter;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.context.annotation.Role;
import org.wu.framework.inner.lazy.orm.spring.processor.LazySchemaAutoCreateProcessor;
import org.wu.framework.lazy.orm.core.config.AbstractLazyOperationAttribute;
import org.wu.framework.lazy.orm.core.config.DdlConfigure;
import org.wu.framework.lazy.orm.core.config.LazyOperationAttribute;
import org.wu.framework.lazy.orm.core.config.ReverseEngineering;
import org.wu.framework.lazy.orm.database.lambda.domain.PersistenceRepositoryFactory;

import java.util.Arrays;
import java.util.List;

/**
 * describe LazyOperationProperties 配置
 *
 * @author Jia wei Wu
 * @date 2022/1/23 3:46 下午
 * @see LazyOperationAttribute
 **/
@Data
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@ConfigurationProperties(prefix = LazyOperationAttribute.LAZY_OPERATION_CONFIG_PREFIX)
public class LazyOperationProperties extends AbstractLazyOperationAttribute implements LazyOperationAttribute {

    /**
     * 打印sql
     */
    @Getter
    boolean printfQuery = false;

    /**
     * 使用；lazy 框架设置schema，自动创建数据库
     * 如：默认url连接
     * spring:
     * datasource:
     * url: jdbc:mysql://127.0.0.1:3306/information_schema?allowMultiQueries=true&useUnicode=true&autoReconnect=true&useAffectedRows=true&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&databaseTerm=SCHEMA
     * username: root #有权限创建数据
     * password: wujiawei
     * driver-class-name: com.mysql.cj.jdbc.Driver
     *
     * @see LazySchemaAutoCreateProcessor
     */
    private boolean enableAutoSchema = false;
    /**
     * 自动填充忽略的数据库
     */
    private List<String> ignoredDatabase = Arrays.asList("mysql", "information_schema", "performance_schema", "sys");
    /**
     * 自动填充时 填充忽略的字段 自增的、含有默认值、可以为null的字段
     */
    private List<String> fillIgnoredFields = Arrays.asList("id");
    /**
     * 自动填充时 最大条数(触发后使用多线程处理)
     */
    private Long fillMaximum = 1024L;
    /**
     * DDL  操作
     *
     * @see LazyOperationAttribute#ddlConfigure
     */

    /**
     * 允许逆向工程 为true时 ReverseEngineering 有效
     */
    private boolean enableReverseEngineering = false;

    /**
     * 事件队列名称
     */
    private String eventQueueName="default_lazy_orm_event";

    /**
     * 逆向工程
     */
    @NestedConfigurationProperty
    private ReverseEngineering reverseEngineering = new ReverseEngineering();

    public void setPrintfQuery(boolean printfQuery) {
        PersistenceRepositoryFactory.printfQuery = printfQuery;
    }


}
